package com.fdb.efp.batch.service.impl.wsd;

import com.fdb.efp.batch.service.facade.wsd.WsdRelatedSheetService;
import com.fdb.efp.nls.service.facade.wsd.WsdRptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 需求编号：2019D0519<br/>
 * 问题编号：<br/>
 * 功能描述：<br/>
 * 开发人员：周才顺<br/>
 * 创建时间：2019/8/1 9:21
 *
 * @Author zhoucs1
 * @Version 1.0
 * @Since 1.0
 */
@Service("wsdRelatedSheetService")
public class WsdRelatedSheetServiceImpl implements WsdRelatedSheetService {

    // 日志记录器
    private Logger logger = LoggerFactory.getLogger(WsdRelatedSheetServiceImpl.class);

    // 网商贷相关表服务
    @Autowired
    @Qualifier("wsdRptService")
    private WsdRptService wsdRptService;

    @Override
    public boolean formData(String batchDate) throws Exception {
        // 校验批次日期是否有配置
        Optional.ofNullable(batchDate).orElseThrow(() -> new Exception("批次日期为空，请检查参数组是否正确配置"));

        // 处理是否成功的标志
        boolean flag = true;


        try {
            // 清空临时表的数据
            wsdRptService.deleteTmpData();

            // 调用存储过程
            wsdRptService.formData("890092_LHD",batchDate);
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
            throw e;
        }

        return flag;
    }
}
